<template>
  <div ref="gamewindowtxet" type="text" readonly="readonly" style="background:black;overflow-y:scroll">
    <ol>
      <li v-for="(line, lineindex) in mudtexts" v-bind:key="lineindex">
        <span v-for="(span, spanindex) in line" v-bind:key="spanindex" :style="{color:span.color}">{{ span.text }}</span>
      </li>
    </ol>
  </div>
</template>

<script>

export default {
  data: function () {
    return this.gdata.data
  },
  components: {
  },
  watch: {
    mudtexts: function () {
      this.$nextTick(function () {
        var windowtxet = this.$refs.gamewindowtxet
        windowtxet.scrollTop = windowtxet.scrollHeight
      })
    }
  },
  methods: {
    scrollbottom: function () {
      // var windowtxet = this.$refs.gamewindowtxet
      // windowtxet.scrollTop = windowtxet.scrollHeight
      this.$nextTick(function () {
        var windowtxet = this.$refs.gamewindowtxet
        windowtxet.scrollTop = windowtxet.scrollHeight
      })
    },
    ongodir: function (dir) {
      var reqinfo = this.wsreq('C2G_ROOM_GO')
      reqinfo.Dir = dir
      this.wssend(reqinfo)
    },
    G2C_Game_Message: function (pid, rsp, success, result) {
      var wdtext = rsp.Text
      if (!(wdtext == null || wdtext === '')) {
        this.jxwdtextmud(wdtext)
      }
    },
    G2C_Chat_Receive: function (pid, rsp, success, result) {
      var msg = rsp.Msg
      var wdtext = '#HIC#'
      var chattype = '闲聊'
      var chatname = msg.Sender
      if (msg.ChatType === this.proto.MapEChatType.谣言) {
        wdtext = '#HIM#'
        chattype = '谣言'
        chatname = '某人'
      } else if (msg.ChatType === this.proto.MapEChatType.房间) {
        wdtext = '#CYN#' + msg.Sender + '说：' + msg.Text
        this.jxwdtextmud(wdtext)
        return
      }
      wdtext += '【'
      wdtext += chattype
      wdtext += '】'
      wdtext += chatname
      wdtext += '：'
      wdtext += msg.Text
      if (!(wdtext == null || wdtext === '')) {
        // this.jxwdtext(wdtext)
        this.jxwdtextmud(wdtext)
      }
    },
    G2C: function (pid, rsp, success, result) {
      switch (pid) {
        case 'G2C_GAME_MESSAGE':
          this.G2C_Game_Message(pid, rsp, success, result)
          break
        case 'G2C_CHAT_RECEIVE':
          this.G2C_Chat_Receive(pid, rsp, success, result)
          break
        case 'G2C_ROOM_INFO':
          var roominfo = rsp.RoomInfo
          var conf = this.conf.ConfigRoom[roominfo.ConfigId]

          var roomText = '#HIR#【#HIG#' + conf.Name + '#HIR#】#NOR#'
          roomText += conf.Desc
          var 出口数目 = roominfo.ListExit.length
          if (出口数目 <= 0) {
            roomText += '【这里没有明显的出口。】'
          } else {
            roomText += '【这里明显的出口是：#HIG#'
            var index = 0
            for (var dir of roominfo.ListExit) {
              if (index === 0) {
              } else if (index === 出口数目 - 1) {
                roomText += '#NOR#和#HIG#'
              } else {
                roomText += '#NOR#、#HIG#'
              }
              roomText += dir.Dir + '#NOR#方#HIG#'
              index++
            }
            roomText += '#NOR#。】'
          }
          this.jxwdtextmud(roomText)
          break
        default:
          break
      }
    }
  }
}
</script>

<style scoped>
</style>
